<?php
namespace app\manage\controller;

use think\Db;
use think\Controller;
use think\Session;

class User extends Controller
{
    public function fault(){
        return $this->fetch();
    }
    public function index(){
        Session::clear();
        return $this->fetch();
    }
    public function systemindex(){
        Session::clear();
        return $this->fetch();
    }
    public function login(){
        $data = input('post.');
        $validate = \think\Loader::validate('Login');
        if (!$validate->check($data)) {
            return $this->error($validate->getError());
        }
        $data = [
            'tel' => input('tel'),
            'pwd' => md5(input('pwd'))
        ];
        $user = Db::name("clubadmin")->where($data)->find();
        if($user){
            if ($user['status'] == '0') {
                return $this->error("登录失败:您的账号已被冻结");
            }
            Db::name("clubadmin")->where($data)->update(['lastlogintime' => date('Y-m-d H:i:s')]);
            $clubname = Db::name("club")->where("clubid",$user['clubid'])->find()['name'];
            Session::set("clubadminid", $user['clubadminid']);
            Session::set("clubname", $clubname);
            Session::set("act","0");
            session_regenerate_id();
            return $this->redirect("clubadmin/clubmanage");
        }
        return $this->error("登录失败:账号密码错误");
    }
    public function login1(){
        $data = input('post.');
        $validate = \think\Loader::validate('Login');
        if (!$validate->check($data)) {
            return $this->error($validate->getError());
        }
        $data = [
            'tel' => input('tel'),
            'pwd' => md5(input('pwd'))
        ];
        $user = Db::name("systemadmin")->where($data)->find();
        if($user){
            Db::name("systemadmin")->where($data)->update(['lastlogintime' => date('Y-m-d H:i:s')]);
            Session::set("systemadminid", $user['systemadminid']);
            Session::set("act","1");
            session_regenerate_id();
            return $this->redirect("systemadmin/clubmanage");
        }
        return $this->error("登录失败:账号密码错误");
    }
    public function logout(){
        Session::clear();
        return $this->redirect("user/index");
    }
    public function systemlogout(){
        Session::clear();
        return $this->redirect("user/systemindex");
    }
}
